﻿using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace spark
{
    public class EventFunction : IExternalEventHandler
    {
        public string componentPath { get; set; }
        public void Execute(UIApplication app)
        {

            if (componentPath != null)
            {
                var document = app.ActiveUIDocument.Document;
                Family family = null;
                Transaction transaction = new Transaction(document);
                transaction.Start("载入族");
                bool b = document.LoadFamily(componentPath, out family);
                if (!b)
                {
                    MessageBox.Show("请删除已有族！");
                    transaction.Commit();
                }
                else
                { 
                    transaction.Commit();
                    MessageBox.Show("载入成功！");
                }
                
                
            }
        }

        public string GetName()
        {
            // throw new NotImplementedException();
            return "EventFunction";
        }
    }
}
